package main

import (
	"errors"
	"time"
	"math/rand"
	"context"
	"fmt"
)

// 没能很好理解第二道题...

func querySaleDatas(ctx context.Context) (int, error){
	select {
	case <-ctx.Done():
		return 400, ctx.Err()
	default:
		context.WithValue(ctx, "count", rand.Int())
		switch ctx.Value("count").(type) {
		case int:
			val, ok := ctx.Value("count").(int)
			if !ok {
				return 400, errors.New("error_msg")
			}
			return val, nil
		}
	}
}

func main() {
	ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()

	go querySaleDatas(ctx)
	select {
	case <-ctx.Done():
		fmt.Println("main", ctx.Err())
	}
}
